Manual.prototype = new Sprite();

function Manual (manPath){
        Sprite.apply(this);
        this.text = new TextField();
        var tFormat = new TextFormat(font, 25, 0);
        tFormat.align = TextFormatAlign.CENTER;
        
        var countDownFormat   = new TextFormat(font, 200, black);
        countDownFormat.align = TextFormatAlign.CENTER;
        this.path = manPath;
        
        this.background = Game._game.bitmaps[Game.picturesPath+"base/cleanbg.jpg"];
        this.background.x = 0;
        this.background.y = 0;
        this.background.visible = true;
        this.addChild (this.background);
        
        this.manualPic = Game._game.bitmaps[manPath+"manual.png"];
        this.manualPic.x = 0;
        this.manualPic.y = 0;
        this.manualPic.visible = true;
        this.addChild (this.manualPic);
        
        this.width = MainContainerWidth;
        this.height = MainContainerHeight;
        this.addChild(this.text);
        this.startButton = new Button("Štart");
        this.startButton.x = (MainContainerWidth - this.startButton.width - MARGIN);
        this.startButton.y = MARGIN;
        this.startButton.addEventListener(MouseEvent.CLICK, buttonStartClick);
        this.addChild(this.startButton);
        this.countDownLabel = new TextField();
        this.countDownLabel.text = 3;
        this.countDownLabel.setTextFormat(countDownFormat);
        this.countDownLabel.width = this.countDownLabel.textWidth;
        this.countDownLabel.height = this.countDownLabel.textHeight;
        this.countDownLabel.x = (MainContainerWidth - this.countDownLabel.textWidth)/2;
        this.countDownLabel.y = (MainContainerHeight - this.countDownLabel.textHeight)/2;
        this.addChild (this.countDownLabel);
        this.countDownLabel.visible = false;
        this.countDownTimer = new Timer (1000);
        this.addChild (this.countDownTimer);
        this.Run = manualRun;
        this.updateCountdownText = updateCountdownText;
}

function buttonStartClick (event){
    var owner = event.target.parent;
    event.target.visible = false;
    owner.manualPic.visible = false;
    owner.countDownLabel.visible = true;
    owner.countDownTimer.TimerStart();
}

function manualRun (){
    if (this.countDownTimer.time == 4){
        this.visible = false;
        this.countDownTimer.TimerStop();
        this.parent.Start();
        return;
    }
    this.updateCountdownText();
}

function updateCountdownText (){
    this.countDownLabel.text = 3 - this.countDownTimer.time;
    if (this.countDownLabel.text == 0){
        this.countDownLabel.text = "Štart";
        this.countDownLabel.width = this.countDownLabel.textWidth;
        this.countDownLabel.height = this.countDownLabel.textHeight;
        this.countDownLabel.x = (MainContainerWidth - this.countDownLabel.textWidth)/2;
        this.countDownLabel.y = (MainContainerHeight - this.countDownLabel.textHeight)/2;
    }
}